package com.yinxin.wudasuanfa;

import java.util.Scanner;

/**
 * @author yinxin
 * @version 1.0
 * @Description: 排序
 * @date 2022/4/1319:08
 */
public class Day1 {
    public static void main(String[] args) {
        doIt();
    }

    public static void doIt() {
        Scanner Msc = new Scanner(System.in);
        String[] numbers;
        Integer M = Integer.parseInt(Msc.nextLine());
        Scanner arrSc = new Scanner(System.in);
        String arr = arrSc.nextLine();
        numbers = arr.trim().split(" ");
        int[] tenms = new int[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            tenms[i] = Integer.parseInt(numbers[i]);
        }
        int[] result = MaoPao(tenms);
        Scanner Nsc = new Scanner(System.in);
        int N = Integer.parseInt(Nsc.nextLine());
        if (N > M / 2) {
            System.out.println(-1);
        } else {
            if (N == M / 2 && M / 2 == 1) {
                System.out.println(-1);
            } else {
                sum(result, N);
            }
        }
    }

    private static void sum(int[] result, int N) {
        Long res = 0L;
        int[] tmp = new int[N];
        for (int i = 0; i < N; i++) {
            tmp[i] = result[i];
            res += result[i];
        }
        for (int i = result.length - 1; i > result.length - N - 1; i--) {
            for (int i1 : tmp) {
                if (i1 == result[i]) {
                    System.out.println(-1);
                    return;
                }
            }
            res += result[i];
        }
        System.out.println(res);
    }

    public static int[] MaoPao(int[] arr) {
        //外层循环
        for (int i = 0; i < arr.length - 1; i++) {
            //内层循环
            for (int j = 0; j < arr.length - 1 - i; j++) {
                //两两比较
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        return arr;
    }

}
